import EventEmitter from "events";

let eventBusInstance;
class EventBus {
  constructor() {
    this.eventEmitter = new EventEmitter();
  }

  on(eventName, listener) {
    this.eventEmitter.on(eventName, listener);
  }

  emit(eventName, data) {
    this.eventEmitter.emit(eventName, data);
  }
}

export default function getEventBus() {
  if (!eventBusInstance) {
    eventBusInstance = new EventBus();
  }
  return eventBusInstance;
}
